package com.gu.myviewmodel.repo

import android.content.Context
import com.gu.myviewmodel.services.Car
import com.gu.myviewmodel.services.CarDatabase
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class DataBaseRepo @Inject constructor(@ApplicationContext val context: Context) : BaseRepo<Car>() {
    private val databaseApi = CarDatabase.getInstance(context).carDao()
    override suspend fun loadData(): List<Car> {
        return databaseApi.getCars()
    }

    suspend fun insert(list: List<Car>) {
        databaseApi.insertAll(list)
    }

    override suspend fun isEmpty(): Boolean {
        return databaseApi.getCarsNoOrder().isEmpty()
    }

    override suspend fun clear() {
        return databaseApi.deleteOld()
    }

    override fun repoTag() = "RoomRepo"


//    private fun getDataFromDataBase(block: () -> Unit): List<Car>? {
//        val res: List<Car>?
//        contract {
//            callsInPlace(block, InvocationKind.EXACTLY_ONCE)
//        }
//
//    }
}